package com.desire.homework;

import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;

/**
 * @author LittleDesire
 * @description
 * @date 2022-02-10 周四 19:45
 * @since 17
 */
public class _54_获取年月日单独的日期间隔 {
    public static void main(String[] args) {
        //制定格式转换
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyy-MM-dd");

        // 将传入的字符串以fmt的定义的格式解析出来
        LocalDate startDate = LocalDate.parse("2019-03-01", fmt);
        //LocalDate endDate = LocalDate.parse("2020-04-02", fmt);
        LocalDate endDate = LocalDate.now();

        Period period = Period.between(startDate, endDate);
        System.out.println("相差" + period.getYears() + "年" + period.getMonths() + "个月" + period.getDays() + "天");
    }
}
